package airacrobats.main;

import airacrobats.gear.Gear;
import airacrobats.gear.GearListener;
import airacrobats.gear.SplashGear;
import airacrobats.gear.SquadronGear;
import airacrobats.gui.component.AWindow;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.UIManager;
import org.pushingpixels.substance.api.skin.SubstanceChallengerDeepLookAndFeel;

/**
 * This is the class that controls the gears of the game.
 */
public class GearManager implements GearListener
{
    /**
     * Game window.
     */
    private AWindow window;
    /**
     * Current gear.
     */
    private Gear gear;

    /**
     * Starts the game.
     */
    public void init() throws Exception
    {
        UIManager.setLookAndFeel(new SubstanceChallengerDeepLookAndFeel());

        window = new AWindow();
        window.addWindowListener(new WindowAdapter()
        {
            @Override
            public void windowClosing(WindowEvent e)
            {
                if (gear.closing())
                    System.exit(0);
            }
        });
        
        Gear newGear = new SplashGear(this, new SquadronGear(this), null);
        newGear.load();
        
        gearChanging(newGear);
        
        window.setVisible(true);
    }

    /**
     */
    public void gearChanging(Gear gear)
    {
        this.gear = gear;
        window.setContentPane(gear);
        window.pack();
        window.setLocationRelativeTo(null);
        gear.requestFocus();
    }
}
